# @Version  : 1.0
# @Author   : wgq
# @File     : houseOperation.py
# @Date     : 2025/6/10 19:58
houses = [{"id":1,"name":"tom","phone":"123","address":"海淀","rent":800,"status":"已出租"}]
id_count = 1
def printMenu():
    """
    打印功能列表
    :return:
    """
    print()
    print("房屋功能列表".center(32,"="))
    print("1. 增 加 房 屋")
    print("2. 删 除 房 屋")
    print("3. 更 改 房 屋")
    print("4. 查 找 房 屋")
    print("5. 查 看 房 屋 列 表")
    print("6. 退 出 系 统")

def listHouse():
    """
    查看当前房屋列表
    :return:
    """
    print("编号\t\t房主\t\t电话\t\t地址\t\t租金\t\t状态")
    for house in houses:
        for value in house.values():
            print(f"{value}\t\t\t",end = "")
        print()

def addHouse():
    """
    增加房屋信息
    :return:
    """
    global id_count
    id_count += 1
    name = input("请输入房主:")
    phone = input("请输入电话:")
    address = input("请输入地址:")
    rent = float(input("请输入租金:"))
    status = input("请输入状态:")
    house = {"id":id_count,"name":name,"phone":phone,"address":address,"rent":rent,"status":status}
    houses.append(house)

def findHouse(key:int):
    count = 0
    for house in houses:
        if house["id"] == key:
            key = house["id"]
            return count
        count += 1
    return -1

def delHouse(key:int):
    delHouseIndex = findHouse(key)
    if delHouseIndex != -1:
        houses.pop(delHouseIndex)


def printHouse(key:int):
    printHouseIndex = findHouse(key)
    if printHouseIndex != -1:
        print("编号\t\t房主\t\t电话\t\t地址\t\t租金\t\t状态")
        for value in houses[printHouseIndex].values():
            print(f"{value}\t\t\t",end = "")

def updateHouse(key:int):
    updateHouseIndex = findHouse(key)
    house = houses[updateHouseIndex]
    if updateHouseIndex != -1:
        name = input(f"请输入房主({house["name"]}):")
        if len(name) == 0:
            name = house["name"]
        phone = input(f"请输入电话({house["phone"]}):")
        if len(phone) == 0:
            phone = house["phone"]
        address = input(f"请输入地址({house["address"]}):")
        if len(address) == 0:
            address = house["address"]
        rent = input(f"请输入租金({house["rent"]}):")
        if len(rent) == 0:
            rent = house["rent"]
        status = input(f"请输入状态({house["status"]}):")
        if len(status) == 0:
            status = house["status"]
        id_count = house["id"]
        houses[updateHouseIndex] = {"id":id_count,"name":name,"phone":phone,"address":address,"rent":rent,"status":status}



